import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import sys

vmin = 1000
vmax = 1500


if len(sys.argv) > 1:
    file_name = sys.argv[1]
else:
    file_name = 'example.bin'

data = np.fromfile(file_name,dtype='>u2')
print('')
print('-------------------- data information --------------------')
print('data file name : ',file_name)
print('')
print('-------------------- plot information --------------------')
print('frame number : ',round(len(data)/5184))
print('plot picture colors Normalize : 0 to 4095')
print('plot picture frame interval time : 10ms')
data = data.reshape(-1,5184)
fig, ax = plt.subplots()
norm = mpl.colors.Normalize(vmin=vmin,vmax=vmax)
for i in range(len(data)):
    ax.cla()
    data_deal = data[i].reshape(72,72)
    ax.imshow(data_deal)
    ax.set_title("frame {}".format(i))
    pcm = ax.pcolormesh(data_deal,cmap='viridis',norm=norm)
    if i == 0:
        fig.colorbar(pcm, ax=ax)
    plt.pause(0.01)
